<template>
	<view class="page">
		<navBar title="申请退款" bg="#F8F8F8"></navBar>

		<view class="product flex_center">
			<image :src="data.image" mode="aspectFill"></image>
			<view class="name hidden">
				<text>{{ data.name || '' }}</text>
				<view>
					<i>￥</i>{{ data.pay_price || 0 }}
				</view>
			</view>
		</view>

		<view class="from">
			<view class="item flex_r_between" @click="show = true">
				<view class="label flex_c">
					<view>退款原因<i>*</i></view>
				</view>
				<view class="select flex_center">
					<text class="hidden" :style="return_type ? `color: #333;` : ''">{{ return_type || '请至少选择一项' }}</text>
					<u-icon name="arrow-right" color="#9C9C9C" size="24rpx"></u-icon>
				</view>
			</view>

			<view class="item flex_r_between">
				<view class="label flex_c">
					<view>金额</view>
					<text>实际退款金额以到账金额为准</text>
				</view>
				<view class="price hidden">
					￥{{ data.pay_price }}
				</view>
			</view>

			<view class="item flex_r_between">
				<view class="label flex_c">
					<view>退款方式</view>
				</view>
				<view class="type hidden">
					原路退回
				</view>
			</view>

		</view>

		<view class="remark">
			<view class="title">退款说明</view>
			<view class="textarea">
				<textarea maxlength="500" v-model="return_remark" placeholder="请输入"
					placeholder-class="input-placeholder"></textarea>
				<view class="maxlength">{{ return_remark.length }}/500</view>
			</view>
		</view>

		<view class="sign">
			申请退款后不可取消，钱款预期1-3个自然日到账
		</view>

		<view class="btn flex_center">
			<view class="flex_r_around" @click="onReturn">
				<text>申请退款</text>
			</view>
		</view>

		<view>
			<u-popup :show="show" @close="show = false" bgColor="transparent">
				<view class="popup">
					<view class="title flex_r_between">
						<view class="block"></view>
						<text>退款原因</text>
						<view class="icon flex_r_around" @click="show = false">
							<u-icon name="close" size="24rpx" color="#131313"></u-icon>
						</view>
					</view>

					<view class="list">
						<view class="item flex_r_between" v-for="(item,index) in list" :key="index"
							@click="return_type = item">
							<view class="label">{{ item }}</view>
							<image :src="`/static/public/select${item == return_type ? '_s' : ''}.png`"
								mode="aspectFill">
							</image>
						</view>
					</view>

					<view class="popup_btn flex_r_around" @click="show = false">
						<text>确定</text>
					</view>

				</view>
			</u-popup>
		</view>

		<u-popup :show="show_modal" mode="center" @close="show_modal = false" bgColor="transparent">
			<view class="modal flex_c">

				<view class="title">提示</view>
				<view class="text">{{ modal_msg }}</view>
				<view class="modal_btn flex_r_between">
					<view class="item submit flex_r_around" @click="$util.back()">
						<text>我知道了</text>
					</view>
				</view>
			</view>
		</u-popup>

		<wLoading ref="loading"></wLoading>


	</view>
</template>

<script>
	import navBar from '@/compentents/navBar/navBar.vue';
	import wLoading from "@/components/w-loading/w-loading.vue";
	export default {
		components: {
			navBar,
			wLoading
		},
		data() {
			return {
				data: {},
				show: false,

				list: [
					
				],
				show_modal: false,
				modal_msg: '已申请退款',
				flag: true,

				order_id: 0,
				store_id: 0,
				return_remark: '',
				return_type: '',
			}
		},
		methods: {
			getDetail() {
				this.$get('/order/getOrderInfo', {
					order_id: this.order_id
				}).then(res => {
					this.data = res.data;
				})
			},

			onReturn() {
				if (!this.return_type) {
					return this.$util.msg('请选择退款原因');
				}

				if (!this.flag) {
					return;
				}
				this.flag = false;
				this.$refs.loading.open();
				this.$post('/order/returnOrder', {
					order_id: this.order_id,
					return_remark: this.return_remark,
					return_type: this.return_type
				}, false, (res) => {
					this.modal_msg = res.msg;
					this.show_modal = true;
					this.$refs.loading.close();
					this.flag = true;
				}).then(res => {
					this.modal_msg = res.msg;
					this.show_modal = true;
					this.$refs.loading.close();
					this.flag = true;
				});
			},
		
			getStoreConf() {
				this.$get('/order/getStoreConf',{
					store_id:this.store_id
				}).then(res => {
					// 开启自动接单：1=开启
					if(res.data.return_reason){
						this.list = JSON.parse(res.data.return_reason);
					}
				})
			},
		
		
		},

		onLoad(option) {
			if (option.token) {
				uni.setStorageSync('token', option.token);
				uni.setStorageSync('cid', option.cid);
				uni.setStorageSync('terminal', option.terminal);
			}

			this.order_id = option.order_id;
			this.store_id = option.store_id;
			this.getDetail();
			this.getStoreConf();


		}
	}
</script>

<style lang="less" scoped>
	.page {
		background: #F8F8F8;
		min-height: 100vh;
		padding: 0 32rpx 100rpx;
	}

	.product {
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 24rpx 32rpx;

		image {
			width: 128rpx;
			height: 128rpx;
			border-radius: 16rpx;
			color: #ECECF4;
			margin-right: 20rpx;
		}

		.name {
			flex: 1;

			text {
				font-weight: 500;
				font-size: 32rpx;
				color: #131313;
			}

			view {
				i {
					font-size: 24rpx;
					font-style: normal;
				}

				font-weight: 600;
				font-size: 32rpx;
				color: #131313;
			}
		}

	}

	.from {
		margin: 20rpx 0;
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 0 32rpx;
		overflow: hidden;
		border-radius: 24rpx;
		overflow: hidden;

		.item {
			height: 100rpx;
			overflow: hidden;

			.label {
				margin-right: 20rpx;
				align-items: flex-start;

				view {
					font-size: 28rpx;
					color: #131313;
					line-height: 32rpx;

					i {
						font-size: 28rpx;
						font-style: normal;
						color: #FD2A53;
						line-height: 32rpx;
						margin-left: 6rpx;
					}
				}

				text {
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					margin-top: 6rpx;
				}
			}

			.select {
				flex: 1;
				overflow: hidden;

				text {
					font-size: 28rpx;
					color: #999999;
					margin-right: 8rpx;
					flex: 1;
					text-align: right;
				}
			}

			.price {
				flex: 1;
				font-weight: 500;
				font-size: 28rpx;
				color: #FD2A53;
				text-align: right;
			}

			.type {
				flex: 1;
				font-size: 28rpx;
				color: #131313;
				text-align: right;
			}
		}
	}

	.remark {
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 32rpx;
		margin-top: 20rpx;

		.title {
			font-size: 28rpx;
			color: #131313;
			line-height: 32rpx;
		}

		.textarea {
			background: #F7F7F7;
			border-radius: 16rpx;
			padding: 24rpx;
			margin-top: 32rpx;

			textarea {
				height: 176rpx;
				font-size: 28rpx;
				color: #333;
			}

			.maxlength {
				font-size: 28rpx;
				color: #999999;
				line-height: 40rpx;
				text-align: right;
			}
		}

	}

	.sign {
		width: 100vw;
		height: 80rpx;
		background: #FFFFFF;
		padding: 0 32rpx;
		font-size: 24rpx;
		color: #666666;
		line-height: 80rpx;
		position: fixed;
		bottom: 130rpx;
		left: 0;
		z-index: 99;
	}

	.btn {
		width: 100vw;
		height: 130rpx;
		padding: 0 32rpx 30rpx;
		background: #FFFFFF;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99;
		flex-direction: row-reverse;

		view {
			width: 228rpx;
			height: 72rpx;
			background: #FD2A53;
			border-radius: 40rpx;

			text {
				font-weight: 500;
				font-size: 28rpx;
				color: #FFFFFF;
				line-height: 40rpx;
			}
		}
	}

	.popup {
		width: 100vw;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		padding: 40rpx 32rpx;

		.title {
			margin-bottom: 30rpx;

			text {
				font-weight: 500;
				font-size: 32rpx;
				color: #131313;
				line-height: 44rpx;
			}

			.block {
				width: 56rpx;
				height: 56rpx;
			}

			.icon {
				width: 56rpx;
				height: 56rpx;
				background: #F1F1F1;
				border-radius: 28rpx;
			}
		}

		.list {
			.item {
				padding: 16rpx 0;

				.label {
					font-size: 28rpx;
					color: #131313;
					line-height: 32rpx;
				}

				image {
					width: 36rpx;
					height: 36rpx;
				}
			}
		}

		.popup_btn {
			width: 686rpx;
			height: 88rpx;
			background: #FD2A53;
			border-radius: 16rpx;
			margin-top: 60rpx;

			text {
				font-size: 32rpx;
				color: #FFFFFF;
			}
		}

	}

	.modal {
		width: 616rpx;
		background: #FFFFFF;
		border-radius: 40rpx;
		padding: 16rpx 44rpx 62rpx;

		.title {
			font-weight: 500;
			font-size: 36rpx;
			color: #FD2A53;
			line-height: 50rpx;
			margin: 16rpx 0 30rpx;
		}

		.text {
			font-size: 28rpx;
			color: #666666;
			line-height: 40rpx;
		}

		.modal_btn {
			margin-top: 42rpx;

			.item {
				height: 88rpx;
				border-radius: 44rpx;
				width: 320rpx;

				text {
					font-size: 28rpx;
				}
			}

			.submit {
				background: #FD2A53;

				text {
					color: #FFF;
				}
			}
		}

		.icon {
			width: 100%;
			flex-direction: row-reverse;
		}
	}
</style>